#include <bits/stdc++.h>
using namespace std;
const int N = 105;

bool vis[1005];
int n, mx = INT_MIN;
struct p{
    int s, e;
    void input() { cin >> s >> e; }
    int get() {
        int ans = 0;
        for (int i = s + 1; i <= e; ++i)
            if (!vis[i]) ++ans, vis[i] = 1;
        return ans;
    }
} a[N];
int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) a[i].input();
    for (int i = 1, tmp; i <= n; ++i) {
        tmp = 0;
        memset(vis, 0, 1005);
        for (int j = 1; j <= n; ++j) {
            if (i == j) continue;
            tmp += a[j].get();
        }
        mx = max(mx, tmp);
//        cout << tmp << endl;
    }
    cout << mx;
    return 0;
}